
package com.android.fitnesscenter.view.server;

import org.json.JSONException;
import org.json.JSONObject;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.android.fitnesscenter.R;
import com.android.fitnesscenter.utils.ToastHelper;
import com.android.fitnesscenter.view.BaseActivity;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.lidroid.xutils.view.annotation.event.OnClick;

public class ServerManagerLoginActivity extends BaseActivity {

    @ViewInject(R.id.edtxt_username)
    private EditText edtxt_username;

    @ViewInject(R.id.edtxt_password)
    private EditText edtxt_password;

    @ViewInject(R.id.btn_login)
    private Button btn_login;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.server_manager_login_layout);
        ViewUtils.inject(this);
        initTitleBar(getString(R.string.txt_manager_login));
        ibtn_back.setVisibility(View.GONE);
        ibtn_more.setVisibility(View.GONE);
    }

    @OnClick(R.id.btn_login)
    public void btn_login(View view) {
        String username = "";
        if (edtxt_username != null && edtxt_username.getText() != null) {
            username = edtxt_username.getText().toString();
        }
        String password = "";
        if (edtxt_password != null && edtxt_password.getText() != null) {
            password = edtxt_password.getText().toString();
        }
        if (TextUtils.isEmpty(username) || TextUtils.isEmpty(password)) {
            ToastHelper.getInstance().showShortMsg("用户名或密码为空!");
        } else {
            login(FROM_SERVER_MANGER_ACTIVITY, username, password);
        }
    }

    @Override
    protected void parseLoginResult(JSONObject jsonObject) throws JSONException {
        String token = jsonObject.getString("token");
        mSharePrefsHelper.setString("token", token);
        Intent intent = new Intent(ServerManagerLoginActivity.this, ServerAuditListActivity.class);
        startActivity(intent);
        finish();

    }

    @Override
    protected void titlebarMethod(int id) {

    }

}
